#version 330

struct DirectionalLight{
    vec3 osDirection; // object space
    vec3 ambientColor;
    vec3 diffuseColor;
};

uniform mat4 objectWorldViewProjection;
uniform vec3 osEyePosition; // object space
uniform DirectionalLight light;

// Per vertex input
layout(location = 1) in vec2 uv;
layout(location = 2) in vec3 tangent;
layout(location = 3) in vec3 binormal;
layout(location = 4) in vec3 normal;
layout(location = 5) in vec3 vertex;

// Per fragment output
out vec3 f_tsVertexToLight;
out vec3 f_tsHalfAngle;
out vec2 f_uv;

void main(){
    f_uv=uv;

    mat3 osToTs = transpose(mat3(tangent,binormal,normal));
    vec3 tsVertexToEye = osToTs * ( osEyePosition - vertex);
    
    f_tsVertexToLight= osToTs * ( -light.osDirection );

    f_tsHalfAngle = normalize( normalize(f_tsVertexToLight) + normalize(tsVertexToEye) );

    // Apply the default transformation to the vertex
    gl_Position = objectWorldViewProjection * vec4(vertex,1.);
}
